import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {ApiProvider} from "../../providers/api/api";
import {AllRankingPage} from "../all-ranking/all-ranking";

/**
 * Generated class for the PersonRankingPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-person-ranking',
  templateUrl: 'person-ranking.html',
})
export class PersonRankingPage {
  student_id;
  class_course_id;

  attentScore;
  viewSourceScore;
  answerExerciseScore;
  rank;

  constructor(public navCtrl: NavController, public navParams: NavParams,public http:ApiProvider) {
  }

  ionViewDidEnter()
  {
    this.student_id=this.navParams.get("student_id");
    this.class_course_id=this.navParams.get("class_course_id");

    this.showPersonalRanking();
  }

  /**
   * 显示相应班课的个人排名
   */
  showPersonalRanking()
  {
    this.http.post("/userstu/myPercent.do",{studentId:this.student_id,class_course_id:this.class_course_id}).subscribe(item=>{
      if(item["Code"]=="11111111")
      {
        this.http.showToast(item["Message"],"bottom");
      }
      else
      {

        this.attentScore=item["percentList"][0]["attenCnt"];
        this.viewSourceScore=item["percentList"][0]["experience"];
        this.answerExerciseScore=item["percentList"][0]["score"];

        this.rank=item["rownum"];
      }
    });
  }

  /**
   * 跳转至全班排名
   */
  showAllRanking()
  {
    this.navCtrl.push(AllRankingPage,{class_course_id:this.class_course_id});
  }
}
